Matrix product operators

Sparse matrix operators

class qtealeaves.mpos.SparseMatrixOperator(is_first, is_last, do_vecs)[source]

A single indexed sparse MPO representing one site.

Arguments

is_firstbool

Flag if sparse matrix operator represents first site.

is_lastbool

Flag if sparse matrix operator represents last site.

do_vecsbool

For periodic boundary conditions aiming at actual matrices for all sites, set to False. For True, the first and last site will use vectors.

add_term(sp_mat, pstrengthid, prefactor)[source]

Add another sparse MPO to the existing one via terms.

Arguments

sp_matinteger np.ndarray

Index matrix of MPO to be added.

pstrengthidinteger np.ndarray

Index of parameters of the MPO to be added.

prefactornp.ndarray

Prefactors of the MPO to be added.

get_list_tensors()[source]

Generate a list of the unique indices used in the MPO.

write(fh)[source]

Write out the sparse MPO compatible with reading it in fortran.

Arguments

fhopen filehandle

Information about MPO will be written here.

class qtealeaves.mpos.SparseMatrixOperatorPy(is_first, is_last, do_vecs, operator_eye)[source]

Sparse MPO matrix for one site and the python implementation.

add_term(sp_mat, pstrength, prefactor, weight, mapping)[source]

Adding a non-local terms via its SPO matrix.

Arguments

sp_mat : np.ndarray

pstrength : parameterized couplings via integer ID appearing again in mapping

prefactor : scalar constant coupling

weight : combining pstrength and prefactor with initial values

mappingdict, mapping integers from pstrength into parameterized values

(where values can be strings, scalars, callables).

collapse(params)[source]

Collapse function recalculates local and interaction terms based on the new couplings passed via params dictionary.

collapse_interactions(params)[source]

Collapse function recalculates interaction terms based on the new couplings passed via params dictionary.

collapse_local(params)[source]

Combine all local terms and write them in its element.

convert(dtype, device)[source]

Convert data type and device.

copy()[source]

Actual copy of instance.

property device

Device where the tensor is stored.

property dtype

Data type of the underlying arrays.

matrix_multiply(other, cidx_self, cidx_other, perm_out=None)[source]

Contract two sparse MPOs (rows/cols contracted automatically, permutation has to be on full).

property ndim

Rank of the underlying tensor extracted from the first element.

tensordot_with_tensor(tensor, cidx_self, cidx_tensor, perm_out=None)[source]

Execute contraction of sparseMPO with tensors.

tensordot_with_tensor_left(tensor, cidx_tensor, cidx_self, perm_out=None)[source]

Execute contraction of tensor with sparse MPO (tensor first arg in tensordot).

update_couplings(params)[source]

Update the coupling with a new params dictionary.

Sparse matrix product operators

class qtealeaves.mpos.SparseMPO(num_sites, operators, do_vecs=True)[source]

Representation of a sparseMPO for python.

add_dense_mpo_list(dense_mpo_list, params, indexed_spo=True)[source]

Add terms for DenseMPOList to the SparseMPO.

contr_to_eff_op(tensor, pos, pos_links, idx_out)[source]

Contract operator lists with tensors T and Tdagger to effective operator.

contract_tensor_lists(tensor, pos, pos_links, custom_ops=None)[source]

Linear operator to contract all the effective operators around the tensor in position pos. Used in the optimization.

convert(dtype, device)[source]

Convert underlying array to the speificed data type inplace. Original site terms are preserved.

property device

Device where the tensor is stored.

property dtype

Data type of the underlying arrays.

property num_sites

Return the number of sites in the underlying system.

print_summary()[source]

Print summary of computational effort.

setup_as_eff_ops(tensor_network, measurement_mode=False)[source]

Set this sparse MPO as effective ops in TN and initialize.

to_str()[source]

String representation with sparse-matrix elements.

update_couplings(params)[source]

Load couplings from an update params dictionary.

class qtealeaves.mpos.SparseMatrixProductOperator(params, model, operator_map, param_map)[source]

Indexed sparse MPO for a set of sites.

Arguments

paramsdict

Parameterization of a simulation.

modelinstance of QuantumModel

The physical model to be converted into an MPO.

operator_mapdict

Mapping the operators to their integer IDs.

param_mapdict

Mapping the parameters to their integer IDs.

add_terms(sp_mat_ops_list)[source]

Add a list of SparseMatrixOperators to the existing one in-place.

Arguments

sp_mat_ops_listlist of SparseMatrixOperators

Another interaction to be added to the MPO.

write(fh)[source]

Write out the sparse MPO compatible with reading it in fortran.

Arguments

fhopen filehandle

Information about MPO will be written here.

Tensor product operators

class qtealeaves.mpos.TensorProductOperator(params, model, operators, tensor_network, device='cpu')[source]

Effective operator class. It contains the effective operators in a vector with as many entries as links. The first num_physical_links are always used to store the physical hamiltonian.

TODO: add read/write method for fortran

Parameters

params:

The simulation parameters

model: QuantumModel

Quantum model defining the quantum operator

operators: TNOperators

Class containing the tensors of the operators

tensor_network: tensor network class

Tensor network on which links the efficient operator is defined

devicestr, optional

Device of the computation. Default to “cpu”.

add_operator(name, op)[source]

Add an operator op named name to the list of operators

Parameters

namestr

String identifier of the operator

opnp.ndarray

Matrix of the operator

contr_to_eff_op(tensor, pos, pos_links, idx_out)[source]

Contract operators lists with tensor T and its dagger. Return effective Hamiltonian operators along idx_out (relative to T), resulting from contraction.

Parameters

T: np.ndarray

Tensor of the TTN to contract

ops_list: list of lists of Operator

list of local operator lists, each corresponding to a specific link.

idx_list: list of ints

link indices (relative to T), each corresponding to a local operator list in ops_list.

Returns

list

list of Operators after contractions

contract_tensor_lists(tensor, pos, pos_links, custom_ops=None)[source]

Linear operator to contract all the effective operators around the tensor in position pos. Used in the optimization.

Parameters

vectorinstance of _AbstractQteaTensor

tensor in position pos in vector form

poslist of int

list of [layer_idx, tensor_idx]

custom_opslist of effective operators

Must be sorted, must match number of links

Returns

np.ndarray

vector after the contraction of the effective operators

convert(dtype, device)[source]

Convert underlying array to the speificed data type inplace. Original site terms are preserved.

property device

Device where the tensor is stored.

property dtype

Data type of the underlying arrays.

classmethod from_mpo_list(dense_mpo_list, tensor_network)[source]

Construct a TPO from DenseMPOList.

classmethod from_mpo_list_num_sites(dense_mpo_list, num_sites)[source]

Construct a TPO from DenseMPOList and the number of sites.

property num_sites

Return the number of sites in the underlying system.

property ops

Retrieve the dictionary of operators

setup_as_eff_ops(tensor_network, measurement_mode=False)[source]

Set this sparse MPO as effective ops in TN and initialize.

update_couplings(params)[source]

Update term with new parameter dictionary.

class qtealeaves.mpos.IndexedOperator(op, op_id, coeff)[source]

Class of operator with an index, to keep track of tensor product operators in the TTN, i.e. MPOs where the bond dimension is 1

Parameters

opnp.ndarray or str

Numpy array representing the operator or string of the operator

op_idint

Integer op_id of the operator. Operators with the same op_id are considered to belong to the same MPO

coeffcomplex

Coefficient of the operator

property coeff

Coefficient property

convert(dtype, device, stream=None)[source]

Convert data type and device of relevant attributes in this instance.

property device

Device where the tensor is stored.

property dtype

Data type of the underlying arrays.

property op

Operator property

property op_id

Operator ID property

Indexed tensor product operators

class qtealeaves.mpos.ITPOTerm(do_indexing=True, enable_update=False)[source]

Single iTPO term either for Hamiltonian or inside effective operators.

add_local(operator, prefactor, strength, pstrength, is_oqs)[source]

Add a local term to the iTPOTerm when building a Hamiltonian.

add_term(tpo_id, operator, link_inds, prefactor, strength, pstrength, is_oqs)[source]

Add an interaction term to the iTPOTerm when building a Hamiltonian.

collect_measurements()[source]

Iterator to yield all iTPO-IDs and values of measurements.

convert(dtype, device, stream=None)[source]

Convert underlying array to the specified data type inplace.

copy()[source]

Actual copy of instance.

delete_or_cache_tensors(inds)[source]

Delete or cache entries (used to remove terms which contracted to local.

property device

Device where the tensor is stored.

property dtype

Data type of the underlying arrays.

empty_copy(other=None, do_copy_meas_vec=False)[source]

Make a copy of the settings of a term without entries.

property enable_update

Property if update of time-dependent couplings is enabled.

static get_case_funcs()[source]

Construct the mapping between contraction cases as integers and their functions.

Details

The cases and their IDs are a one-to-one copy from the fortran code. At the beginning, we had even more of them with every possible combination of contracting rank-3 and rank-4 MPOs with 0, 1, and 2 matching horizontal links. Now, they contain only rank-4 MPOs with 1 and matching horizontal links plus the local term rules at -10, -20. To simplify coding, the cases have each their own function (where in fortran it was still a select case).

Copy-pasted from each-functions docstring:

1) only left has TPO-ID 7) lr and rl match to local term 8) ll and rr match to local term 34) match rl and keeping as TPO-ID 43) match lr and keeping as TPO-ID 53) match ll and keeping as TPO-ID 63) match rr and keeping as TPO-ID 99) only right has TPO-ID -10) local term in left -20) local term in right

get_index_copy_operator(idx)[source]

Copy a tensor and return index of copy.

get_index_operator(operator)[source]

Get an index for an operator; created if not existing yet.

get_max_tpo_id()[source]

Get maximum TPO ID in this term.

property has_oqs

Return flag if the iTPOTerm contains any open system term.

property idx_eye

By convention, we will set the “eye” tensor at key -2.

iter_tpo_ids()[source]

Iterator over all TPO IDs present.

matrix_multiply(other, cidx_self, cidx_other, eye_a=None, eye_b=None, perm_local_out=None, ctens=None)[source]

Contract of two iTPOTerms.

Arguments

otherinstance of iTPOTerm

Right / second term in the multiplication

cidx_selflist of ints

Contraction legs for full TPO tensor (local will auto-adapt)

cidx_otherlist of ints

Contraction legs for full TPO tensor (local will auto-adapt)

eye_ainstance of _AbstractQteaTensor or None, optional

If self is not a rank-4 iTPOTerm, pass what should be used as identity. Default to None

eye_binstance of _AbstractQteaTensor or None, optional

If other is not a rank-4 iTPOTerm, pass what should be used as identity. Default to None

perm_local_outlist of ints or None, optional

Permutation of output (full TPO tensor will auto-adapt) (MPO links will be permuted in first and last place automatically) Default to None

ctensNone or ITPOTerm

If present, update mode is activating which assumes that only a scalar weight has changed.

run_measurements(ket, idx_out, link_weights)[source]

Run the measurements on the iTPOTerm, i.e., on all stored local tensors.

sanity_check()[source]

Quick set of checks that the iTPOTerm fulfills certain criteria.

set_meas_status(do_measurement)[source]

Set the measurement status of this iTPOTerm.

tensordot_with_tensor(tensor, cidx_self, cidx_tensor, perm_local_out=None, ctens=None)[source]

Execute contraction of iTPOTerm with tensors. Uncontracted non-MPO legs of self go before uncontracted non-MPO legs of tensor.

Arguments

tensorinstance of _AbstractQteaTensor

Tensor in the contraction as right/second tensor.

cidx_selflist of ints

Contraction legs for full TPO tensor (local will auto-adapt)

cidx_tensorlist of ints

Contraction legs for the tensor

perm_local_outlist of intes

Permutation of output (full TPO tensor will auto-adapt)

ctensNone or ITPOTerm

If present, update mode is activating which assumes that only a scalar weight has changed.

Returns

ctensITPOTerm

Result of contraction.

tensordot_with_tensor_left(tensor, cidx_tensor, cidx_self, perm_local_out=None, ctens=None)[source]

Execute contraction of iTPOTerm with tensors. Uncontracted non-MPO legs of tensor go before uncontracted non-MPO legs of self.

Arguments

tensorinstance of _AbstractQteaTensor

Tensor in the contraction as right/second tensor.

cidx_tensorlist of ints

Contraction legs for the tensor

cidx_selflist of ints

Contraction legs for full TPO tensor (local will auto-adapt)

perm_local_outlist of intes

Permutation of output (full TPO tensor will auto-adapt)

ctensNone or ITPOTerm

If present, update mode is activating which assumes that only a scalar weight has changed.

Returns

ctensITPOTerm

Result of contraction.

to_str(ind_offset=0)[source]

String of values that are used for actual simulation.

update_couplings(params)[source]

Update the coupling with a new params dictionary.

class qtealeaves.mpos.ITPOSites(num_sites, do_indexing, enable_update)[source]

iTPOSites contains the physical terms.

add_dense_mpo_list(dense_mpo_list)[source]

Add terms from a DenseMPOList to the iTPO sites.

class_allowed

alias of ITPOTerm

get_max_tpo_id()[source]

Loop over all sites to get the maximal TPO ID.

property has_oqs

Flag if MPO has Lindblad terms (just present, not looking at coupling).

to_dense_mpo_list(params)[source]

Convert site terms into dense MPO list.

to_str()[source]

Generate a string with information on he Hamiltonian (site terms).

update_couplings(params)[source]

Load couplings from an update params dictionary.

class qtealeaves.mpos.ITPO(num_sites, do_compress=False, do_indexing=True, enable_update=False)[source]

iTPO term with Hamiltonian and effective operators, e.g., for ground state search.

Arguments

num_sitesint

Number of sites in the system, e.g., qubits.

do_compressbool, optional

Flag if compression should be activated (True). Default False (no compression).

do_indexingbool, optional

Flag if indexing should be used (True) or if running as TPO (False). Default to True

enable_updatebool, optional

Flag if smart update of time-dependent parameters should be activated (True). Activation also caches additional states on top of the effective operators. Default to False (no smart update).

Details

The indexed tensor product operator comes in different flavors:

  • TPO : without indexing, pass do_indexing flag.

  • iTPO : with indexing, only unique operators are contracted (default)

  • iuTPO : iTPO with smart update for time-evolution: pass flag enable_update on initialization, moreover do_update has to be set and unset when updating the coupling of the Hamiltonian.

  • icTPO : iTPO with compression, set flag do_compress, which is beneficial for systems with many interactions.

  • iucTPO : iTPO with compression and smart update for time-dependent parameters.

add_contraction_counters(other)[source]

Add a contraction counter in-place.

add_dense_mpo_list(dense_mpo_list)[source]

Add terms from a DenseMPOList to the iTPO sites.

collect_measurements(num_terms=None)[source]

Collect the measurements from measurement setup of iTPO.

compress(pos_tuple)[source]

Compress iTPOTerm at a given position.

Arguments

pos_tupletuple

position of the effective operator to be compressed via two tensor positions

Details

Considering an eight-site MPS-like structure with all-to-all two-body interactions the terms by default at link between sites 6 and 7 are

  • 1 acting at 7 and 8

  • 2 acting at 7 and 8

  • 3 acting at 7 and 8

  • 4 acting at 7 and 8

  • 5 acting at 7 and 8

  • 6 acting at 7 and 8

and will be compressed to

  • (1 + 2 + 3 + 4 + 5 + 6) acting at 7

  • (1 + 2 + 3 + 4 + 5 + 6) acting at 8

Thus, compression makes potentially sense for many interactions and if more than half of the system is integrated into an effective operator. The latter is checked to avoid unnecessary execution.

contr_to_eff_op(tensor, pos, pos_links, idx_out)[source]

Contract operator lists with tensors T and Tdagger to effective operator.

Arguments

tensor_AbstractQteaTensor

Tensor to be contracted to effective operator.

posint, tuple (depending on TN)

Position of tensor.

pos_linkslist of int, tuple (depending on TN)

Position of neighboring tensors where the links in tensor lead to.

idx_outint

Uncontracted link to be used for effective operator.

contract_tensor_lists(tensor, pos, pos_links, custom_ops=None)[source]

Linear operator to contract all the effective operators around the tensor in position pos. Used in the optimization.

Arguments

tensor_AbstractQteaTensor

Tensor to be contracted to effective operator.

posint, tuple (depending on TN)

Position of tensor.

pos_linkslist of int, tuple (depending on TN)

Position of neighboring tensors where the links in tensor lead to.

custom_opsNone or list of ITPOTerm

Ordered list of iTPO terms for tensor, which should be used instead of information in pos and pos_links.

convert(dtype, device)[source]

Convert underlying array to the specified data type inplace. Original site terms are preserved.

property device

Device where the tensor is stored.

property do_update

Status of the flag for doing update of effective operators.

property dtype

Data type of the underlying arrays.

get_ctens_for_update(key, identifier)[source]

Extract a tensor for update of time-dependent coupling from cache.

Arguments

keyimmutable

Key from effective operator to be built serving as base key.

identifier :

Extension to identity step when building effective operator.

Returns

ctensinstance of ITPOTerm or None

Retrieve tensor from cache if updates are enabled.

ukeystr or None

Key for storing tensor again.

property has_oqs

Flag if MPO has Lindblad terms (just present, not looking at coupling).

property num_sites

Return the number of sites in the underlying system.

print_summary()[source]

Print summary of computational effort.

set_ctens_for_update(ukey, ctens)[source]

Set a tensor for time-dependent coupling updates (if enabled).

set_meas_status(do_measurement=True)[source]

Set the measurement status for all iTPOTerms in iTPOSites.

setup_as_eff_ops(tensor_network, measurement_mode=False)[source]

Set this sparse MPO as effective ops in TN and initialize.

to_dense_mpo_list(params, do_initialize=True)[source]

Return the dense MPO form of the site terms, requires params dict.

to_str()[source]

Generate a string with information on the effective operators.

update_couplings(params)[source]

Load couplings from an update params dictionary.

Dense matrix product operators

class qtealeaves.mpos.MPOSite(site, str_op, pstrength, weight, operators=None, params=None)[source]

One site in a dense MPO term.

Arguments

siteinteger

Site index.

str_opstr

Key for the operator.

pstrengthpstrength, callable, numeric

Containing the parameterization of the term.

weightscalar

Scalar constant prefactor.

operatorsTNOperators or None

If present, operators will be directly extracted.

paramsdict or None

If present, parameterization will be directly extracted.

copy_with_new_op(operator)[source]

Create a copy of self, but without replacing the operator with the one passed. Corresponding string identifier will be set to None.

initialize(operators, params)[source]

Resolve operators and parameterization for the given input.

set_op(operators)[source]

Resolve operators for the given input.

set_param(params)[source]

Resolve parameterization for the given input.

property total_scaling

Returns the scaling combining params and weight.

class qtealeaves.mpos.DenseMPO(sites=None, convergence_parameters=None, is_oqs=False, tensor_backend=<qtealeaves.tensors.tensor_backend.TensorBackend object>, require_singvals=False, local_dim=2)[source]

Dense MPO as a list of :class:`MPOSite’s.

add_identity_on_site(idx, link_vertical)[source]

Add identity with the correct links to neighboring terms on site idx.

Parameters

idxint

Site to which add the identity. Goes from 0 to num sites in a system.

link_verticallink as returned by corresponding QteaTensor

Needed to build the local Hilbert space (in case it is different across the system).

append(elem)[source]

Overwriting append to extend as well the list of singvals.

apply_projective_operator(site, selected_output=None, remove=False)[source]

No measurements in MPO

build_effective_operators(measurement_mode=False)[source]

Pass

class_allowed

alias of MPOSite

Compresses links between sites in a dense MPO by performing a QR or SVD, optionally performs the additional truncation along the way.

Parameters

idx_startint

MPO site from which to start the compression.

idx_endint

MPO site on which to end the compression.

truncBoolean, optional

If True, the truncation will be done according to the conv_params. Default to False.

conv_paramsTNConvergenceParameters, optional

Convergence parameters for the truncation. Must be specified if trunc is set to True. Default to None.

classmethod from_matrix(matrix, sites, dim, conv_params, tensor_backend=<qtealeaves.tensors.tensor_backend.TensorBackend object>, operators=<qtealeaves.operators.tnoperators.TNOperators object>, pad_with_identities=False)[source]

For a given matrix returns dense MPO form decomposing with SVDs

Parameters

matrixQteaTensor | ndarray

Matrix to write in (MPO) format

sitesList[int]

Sites to which the MPO is applied

dimint

Local Hilbert space dimension

conv_paramsTNConvergenceParameters

Input for handling convergence parameters. In particular, in the LPTN simulator we are interested in: - the maximum bond dimension (max_bond_dimension) - the cut ratio (cut_ratio) after which the singular values in SVD are neglected, all singular values such that \(\lambda\) /\(\lambda_max\) <= \(\epsilon\) are truncated

tensor_backendinstance of TensorBackend

Default for None is QteaTensor with np.complex128 on CPU.

pad_with_identities: bool, optional

If True, pad with identities the sites between min(sites) and max(sites) that have no operator. Default to False.

Return

DenseMPO

The MPO decomposition of the matrix

classmethod from_statevector(statevector, local_dim=2, conv_params=None, tensor_backend=None)[source]

No statevector for operators

classmethod from_tensor_list(tensor_list, conv_params=None, iso_center=None, tensor_backend=<qtealeaves.tensors.tensor_backend.TensorBackend object>, operators=<qtealeaves.operators.tnoperators.TNOperators object>, sites=None)[source]

Initialize the dense MPO from a list of tensors

Parameters

tensor_listList[QteaTensor] | List[MPOSite]

Matrix to write in (MPO) format

conv_paramsTNConvergenceParameters, None

Input for handling convergence parameters. Default to None

iso_centerNone, int, List[int], str, optional

If None, the center is None. If str, the iso center is installed If int, the iso center is that integer. Default is None

tensor_backendinstance of TensorBackend

Default for None is QteaTensor with np.complex128 on CPU.

operators: TNOperators, optional

Operator class

sitesList[int], None

Sites to which the MPO is applied. If None, they are assumed to be [0, 1, …, len(tensorlist)-1]. Default to None

Return

DenseMPO

The MPO decomposition of the matrix

static generate_mpo_identity(left_bd, local_dim, right_bd, tensor_backend)[source]

Generate an identity in MPO form with given dimensions

Pass

Pass

Get the position of the partner tensor to use in the link expansion subroutine

Parameters

posint | Tuple[int]

Position w.r.t. which you want to compute the partner

Returns

int | Tuple[int]

Position of the partner

int

Link of pos pointing towards the partner

int

Link of the partner pointing towards pos

get_rho_i(idx)[source]

No density matrix for operators

get_tensor_of_site(idx)[source]

Return the tensor representing the MPO operator at site idx

initialize(operators, params)[source]

Resolve operators and parameterization for the given input for each site.

classmethod mpi_bcast(state, comm, tensor_backend, root=0)[source]

Broadcast a whole tensor network.

Arguments

stateDenseMPO (for MPI-rank root, otherwise None is acceptable)

State to be broadcasted via MPI.

commMPI communicator

Send state to this group of MPI processes.

tensor_backendTensorBackend

Needed to identity data types and tensor classes on receiving MPI threads (plus checks on sending MPI thread).

rootint, optional

MPI-rank of sending thread with the state. Default to 0.

norm()[source]

Pass

property num_sites

Length of the Dense MPO

pad_identities(num_sites, eye_ops)[source]

Pad identities on sites which are not in MPO yet respecting the symmetry.

classmethod read(filename, tensor_backend, cmplx=True, order='F')[source]

Read a MPO from a formatted file.

Pass

property sites

Generate list of site indices.

sort_sites()[source]

Sort sites while and install matching link for symmetries.

to_dense(true_copy=False)[source]

Convert into a TN with dense tensors (without symmetries).

to_statevector(qiskit_order=False, max_qubit_equivalent=20)[source]

No statevector for operators

write(filename, cmplx=True)[source]

Write the TN in python format into a FORTRAN compatible format.

class qtealeaves.mpos.DenseMPOList(*args)[source]

Collection of dense MPOs, i.e., for building iTPOs or other MPOs.

class_allowed

alias of DenseMPO

classmethod from_model(model, params, tensor_backend=<qtealeaves.tensors.tensor_backend.TensorBackend object>)[source]

Fill class with QuantumModel and its parameters.

property has_oqs

Return flag if the DenseMPOList contains any open system term.

initialize(operators, params, do_sort=True)[source]

Resolve operators and parameterization for the given input.

sort_sites()[source]

Sort the sites in each DenseMPO.

Abstract effective operators

class qtealeaves.mpos._AbstractEffectiveOperators[source]

Any effective operator or overlap.

Details

Effective operators should implement at least a dictionary functionality where the keys are made of a tuple of two entries, where each entry is the position of a tensor in the tensor network. The key (pos_a, pos_b) provides the effective operators of the tensor at pos_a contracted except for the link leading to the tensor at pos_b. The position itself can be implemented depending on the needs of the tensor networks, e.g., as integer or tuple of integers. Only each link needs a unique pair of positions.

abstract contr_to_eff_op(tensor, pos, pos_links, idx_out)[source]

Calculate the effective operator along a link.

abstract contract_tensor_lists(tensor, pos, pos_links, custom_ops=None)[source]

Linear operator to contract all the effective operators around the tensor in position pos. Used in the optimization.

abstract convert(dtype, device)[source]

Convert underlying array to the specified data type inplace. Original site terms are preserved.

abstract property device

Device where the tensor is stored.

abstract property dtype

Data type of the underlying arrays.

property has_oqs

Return if effective operators is open system (if no support, always False).

abstract property num_sites

Return the number of sites in the underlying system.

print_summary()[source]

Print summary of computational effort (by default no report).

abstract setup_as_eff_ops(tensor_network, measurement_mode=False)[source]

Set this sparse MPO as effective ops in TN and initialize.

Disentanglers

class qtealeaves.mpos.DELayer(num_sites, de_sites, convergence_parameters, local_dim=2, tensor_backend=None, initialize='identity', check_unitarity=True)[source]

Disentangler layer, i.e. the list of disentangler tensors. All the DE tensors must be unitary. One can access a specific tensor by checking DELayer[ind]. In aTTN, DELayer can be accessed via ATTN.de_layer. The leg ordering in disentangler is:

|----------| |----------|

^ ^ | | 0 1

<psi|

Parameters

num_sitesint

Number of sites

de_sites2d np.array, optional

Array with disentangler positions with n rows and 2 columns, where n is the number of disentanglers. Counting starts from 0 and indices are passed as in the mapped 1d system. If set to ‘auto’, the disentangler positions are automatically selected to fit as much disentanglers as possible. Default to ‘random’.

convergence_parameters: TNConvergenceParameters

Class for handling convergence parameters. In particular, in the aTTN simulator we are interested in: - the maximum bond dimension \(\chi\); - the cut ratio \(\epsilon\) after which the singular

values are neglected, i.e. if \(\lambda_1\) is the bigger singular values then after an SVD we neglect all the singular values such that \(\frac{\lambda_i}{\lambda_1}\leq\epsilon\)

local_dim: int, optional

Local Hilbert space dimension. Default to 2.

tensor_backendNone or instance of TensorBackend, optional

Default for None is QteaTensor with np.complex128 on CPU.

initializestring, optional

Define the initialization method. For identities use ‘identity’, for random entries use ‘random’. Default to ‘identity’.

check_unitarityBoolean, optional

If True, all the disentangler tensors are checked for unitarity and an error is raised if the check fails. Default to True.

append(elem)[source]

Overwriting appending an item.

apply_de_to_dense_mpo(de_ind, dense_mpo, tensor_backend)[source]

Contracts DE and DE^dag with a given dense MPO. Since there could be the sites which are in mpo, but not in DE (and vice versa), the function takes care to insert identity operators on appropriate places.

Parameters

de_indint

Index of disentangler which we want to contract with mpo.

dense_mpoDenseMPO

Dense MPO to be contracted with disentangler.

tensor_backend: TensorBackend

Tensor backend of the simulation.

Return

contracted_dense_mpoDenseMPO

Dense MPO contracted with disentangler.

Don’t forget the truncation. Raise a warning if truncating.

check_if_de_eligible(tensor)[source]

Makes several checks and raises an exception if a tensor is not eligible for a disentangler.

property check_unitarity

Flag to check if disentanglers are unitaries.

class_allowed

alias of _AbstractQteaTensor

contract_de_layer(itpo, tensor_backend, params=None)[source]

Contracts the disentangler layer with a given iTPO. The procedure contracts the itpo between DE layer and DE^dag layer as a sandwich:

(DE layer)

(iTPO)

(DE^dag layer)

Parameters

itpoITPO

iTPO which is to be contracted with the DE layer

tensor_backend: TensorBackend

Tensor backend of the simulation.

paramsdict or None, optional

The parameters passed from the simulation. In particular, not needed here. Default to None.

Return

contracted_itpoITPO

iTPO resulting from contracting itpo with DE layer.

property convergence_parameters

Get the convergence settings.

extend(other)[source]

Overwriting extending a list.

insert(index, elem)[source]

Overwriting inserting an item.

property local_dim

Local dimension property

property num_de

Number of disentanglers.

property num_sites

Number of sites property

to_dense_mpo(de_ind, tensor_backend)[source]

Splits the chosen disentangler into left and right operator and stores them as a dense MPO.

Parameters

de_indint

Index of disentangler which we want to store as dense MPO.

tensor_backend: TensorBackend

Tensor backend of the simulation.

Return

dense_deDenseMPO

Dense MPO with left and right disentangler as terms.